#include <time.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include "Debug.h"

class Tscheduler
{
        protected:
                int     m_iATofDay;
	public:
                Tscheduler() { m_iATofDay = 0;  }
		Tscheduler(string at) {
			string sat = at; 
			string sh, ss, sm;
			int lastLoc = 0; 
			int index = (int) sat.find(':', lastLoc);
			if (index > 0) {
				sh = sat.substr(lastLoc, index - lastLoc );
				lastLoc = index+1;
				index = (int) sat.find(':', lastLoc);
				if (index > 0) {
					ss = sat.substr( lastLoc , index - lastLoc );
					sm = sat.substr(index + 1, sat.length() - index - 1); 
				} 
			}
                        m_iATofDay = atoi(sh.c_str())*3600 + atoi(ss.c_str())*60 + atoi(sm.c_str());
                }
		~Tscheduler() {}
		bool Timer(long lt, int expire){
			if( expire  < 1)
				return false;
			lt = lt%86400;
                        if(lt < m_iATofDay)
                        {
                             DEBUG2("lt is too small, please wait for: ", m_iATofDay - lt);  
                             return false;
                        }

			int lc = lt - m_iATofDay;
                        DEBUG2("lt - m_iATofDay = ", lc);  
                        if(lc <= expire)
                            return true;
                        else
                            return false;
		}
                void Print(){  cout << m_iATofDay << endl;  }
};
